package src.first;

import java.lang.reflect.Field;

public class test1 {

    public static void main(String[] args) {
        Student student = new Student();
        Class<?> clazz = student.getClass();
        System.out.println("类的标准名称："+clazz.getCanonicalName());

        try {
            Field id = clazz.getDeclaredField("id");
            System.out.println("设置之前的id:"+id);
            id.setAccessible(true);
            id.setInt(student,10);
            System.out.println("设置后的id值："+student.getId());

            Field name = clazz.getDeclaredField("name");
            System.out.println("设置之前的name:"+student.getName());
            name.setAccessible(true);
            name.set(student,"明日科技");
            System.out.println("设置后的name:"+student.getName());

        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
